package cn.lutu.lutu.service.impl;

import cn.lutu.lutu.mapper.CartMapper;
import cn.lutu.lutu.pojo.dto.CartInsertDTO;
import cn.lutu.lutu.pojo.entity.Cart;
import cn.lutu.lutu.pojo.vo.CartVO;
import cn.lutu.lutu.service.CartService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @date 2023-06-03
 * @author luoyinhan
 * */
@Service
public class CartServiceImpl implements CartService {
    @Autowired
    CartMapper cartMapper;


    @Override
    public int addProductToCart(CartInsertDTO cartInsertDTO,Long id) {
        System.out.println("cartInsertDTO = " + cartInsertDTO + ", id = " + id);
        Cart cart=new Cart();
        BeanUtils.copyProperties(cartInsertDTO,cart);
        cart.setUserId(id);
        return cartMapper.insert(cart);
    }

    @Override
    public int deleteProduct(Long id) {
        return cartMapper.deleteById(id);
    }

    @Override
    public List<CartVO> cartList(Long uid) {
        return cartMapper.selectAll(uid);
    }

    @Override
    public List<CartVO> searchByCategoryAndKeyword(Long categoryId, String keyword,Long uid) {
        return cartMapper.selectByCategoryAndKeyword(categoryId,keyword,uid);
    }
}
